package com.ttx.pattern.example.composite.after;

import java.util.Iterator;

/**
 * 叶子节点， 不含子节点
 * @author TimFruit
 * @date 2019/7/8 15:45
 */

public class Leaf extends Component {
    private String name;

    public Leaf(String name) {
        this.name = name;
    }

    @Override public String getName() {
        return this.name;
    }

    @Override public void operation() {
        System.out.println("leaf: "+name);
    }

    @Override public Iterator<Component> iterator() {
        return new NullIterator();
    }
    
    
    
    private class NullIterator implements Iterator<Component>{

        //表示是否有子节点
        @Override public boolean hasNext() {
            return false;
        }

        @Override public Component next() {
            return null;
        }
    }
}
